package com.aqa.concurrent;

import java.util.stream.IntStream;

/**
 * VM Args: -Xmx20M  -XX:MaxDirectMemorySize = 10M
 *
 */
public class SynchronousQueueTest {


    public static void main(String[] args) {

        Obj obj = new Obj("obj1");
        Obj obj2 = new Obj(obj, "obj2");
//        obj2 = null;
        obj2.next = obj2;
        Obj obj3 = new Obj(obj, "obj3");
//        obj3 = null;
        obj3.next = obj2;
        Obj obj4 = new Obj(obj, "obj4");
//        obj4 = null;
        obj4.next = obj4;
        Obj obj5 = new Obj(obj, "obj5");
//        obj5 = null;
        obj5.next = obj5;
        Obj obj6 = new Obj(obj, "obj6");
//        obj6 = null;
        obj6.next = obj6;
        Obj obj7 = new Obj(obj, "obj7");
//        obj7 = null;
        obj7.next = obj7;
        Obj obj8 = new Obj(obj, "obj8");
//        obj8 = null;
        obj8.next = obj8;
        Obj obj9 = new Obj(obj, "obj9");
//        obj9 = null;
        obj9.next = obj9;
        Obj obj10 = new Obj(obj, "obj10");
//        obj10 = null;
        obj10.next = obj10;
        Obj obj11 = new Obj(obj, "obj11");
//        obj11 = null;
        obj11.next = obj11;
        Obj obj12 = new Obj(obj, "obj12");
//        obj12 = null;
        obj12.next = obj12;
        Obj obj13 = new Obj(obj, "obj13");
//        obj13 = null;
        obj13.next = obj13;
        Obj obj14 = new Obj(obj, "obj14");
//        obj14 = null;
        obj14.next = obj14;
        Obj obj15 = new Obj(obj, "obj15");
//        obj15 = null;
        obj15.next = obj15;
        Obj obj16 = new Obj(obj, "obj16");
//        obj16 = null;
        obj16.next = obj16;
        Obj obj17 = new Obj(obj, "obj17");
//        obj17 = null;
        obj17.next = obj17;

        System.gc();

        System.out.println(obj.value);

    }


}

class Obj {

    public Obj(Obj next, String val) {
        this.next = next;
        this.value = val;
    }

    public Obj(String value) {
        this.value = value;
    }

    int _1MB = 1024 * 1024;
    byte[] data = new byte[2 * _1MB];
    Obj next;
    String value;
}